﻿using System;
using System.Xml.Serialization;
using System.Collections.Generic;

namespace DuLabs.Workflow.Common.Definition
{
    [Serializable]
    [XmlRoot("WorkflowDefinition")]
    public class WorkflowDefinition
    {
        /// <summary>
        /// 获取或设置流程编码
        /// </summary>
        public string FlowCode { get; set; }

        /// <summary>
        /// 获取或设置流程名称
        /// </summary>
        public string FlowName { get; set; }

        /// <summary>
        /// 获取或设置流程是否可用
        /// </summary>
        public bool Enabled { get; set; }

        /// <summary>
        /// 获取或设置创建者信息
        /// </summary>
        public string CreateBy { get; set; }

        /// <summary>
        /// 获取或设置创建时间
        /// </summary>
        public DateTime CreateDate { get; set; }

        /// <summary>
        /// 获取或设置更新者信息
        /// </summary>
        public string UpdateBy { get; set; }
        
        /// <summary>
        /// 获取或设置更新时间
        /// </summary>
        public DateTime UpdateDate { get; set; }

        [XmlElement("Activities")]
        public ActivitiesElement ActivitiesElement { get; set; }

        public WorkflowDefinition()
        {
            this.Enabled = true;
            this.CreateBy = string.Empty;
            this.CreateDate = DateTime.Now;
            this.UpdateBy = string.Empty;
            this.UpdateDate = DateTime.Now;
            this.ActivitiesElement = new ActivitiesElement();
        }

        public static WorkflowDefinition CreateExample()
        {
            WorkflowDefinition workflowDefinition = new WorkflowDefinition();
            workflowDefinition.FlowCode = "流程编码";
            workflowDefinition.FlowName = "流程名称";
            workflowDefinition.CreateBy = "创建者信息";
            workflowDefinition.CreateDate = DateTime.Now;
            workflowDefinition.UpdateBy = "更新者信息";
            workflowDefinition.UpdateDate = DateTime.Now.AddMonths(2);

            ActivityElement activityElement = new ActivityElement();
            activityElement.ActivityCode = "活动编码";
            activityElement.ActivityName = "活动名称";
            activityElement.Enabled = true;

            UserSourceElement userSourceElement = new UserSourceElement();
            userSourceElement.UserSourceType = UserSourceTypeAttribute.SpecifyAndSettings;
            userSourceElement.FilterSeparator = ".";
            userSourceElement.UserElementCollection.Add(new UserElement() { UserCode = "zhaoly1", UserType = UserTypeAttribute.Approver, Filter = "*.*.*.u1" });
            userSourceElement.UserElementCollection.Add(new UserElement() { UserCode = "limin1", UserType = UserTypeAttribute.Approver, Filter = "*.*.*.u1" });
            userSourceElement.UserElementCollection.Add(new UserElement() { UserCode = "zhangpeng1", UserType = UserTypeAttribute.Reader, Filter = "天狮集团.直销事业部.人力资源部.*" });
            userSourceElement.UserElementCollection.Add(new UserElement() { UserCode = "zhaowy", UserType = UserTypeAttribute.Reader, Filter = "天狮集团.直销事业部.人力资源部.*" });

            activityElement.UserSourceElement = userSourceElement;

            workflowDefinition.ActivitiesElement.ActivityElementCollection.Add(activityElement);      

            return workflowDefinition;            
        }

    }
}
